/*
 * 作者：姚俊
 * 功能：审核论著失败的action
 * 日期：2015-05-30
 */
package admin.action.checkFruits;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import admin.email.SendEmail;
import admin.service.fruits.TreatiseService;
import teacher.bean.Award;
import teacher.bean.Flow;
import teacher.bean.Teacher;
import teacher.bean.Treatise;
import teacher.service.treatise;
import teacher.service.flow;
import teacher.service.teacher;

public class TreatiseCheckFailAction {
	
	private Treatise treatise1;
	
	
	
	public Treatise getTreatise1() {
		return treatise1;
	}



	public void setTreatise1(Treatise treatise1) {
		this.treatise1 = treatise1;
	}



	public String execute()
	{
		
		Treatise tre=new TreatiseService().getTreatise(this.getTreatise1());
		Teacher tea=new teacher().SelectTeaByTre(tre);
		if(tea!=null)
		{
			tre.setState(3);
			new TreatiseService().updateTreatise(tre, this.getTreatise1());
			try {
				SendEmail.send_email(tea.getMail(), "论著审核不成功","很遗憾"+tea.getName()+",你的获奖文件审核不通过，已经被驳回！如有疑问，请联系方向管理员。");
			} catch (AddressException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MessagingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
//		流程管理开始
		Treatise a=new Treatise();
		a=new treatise().selectTreatiseById(this.getTreatise1().getTreId());
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Flow f=new Flow();
		f.setFruitId(a.getTreId());
		f.setFruitKind(2);
		f.setDirDo(2);
		f.setDirTime(df.format(new Date()));
		f.setSubDo(1);
		f.setSubTime(df.format(new Date()));
		f.setTeaDo(2);
		f.setTeaTime(df.format(new Date()));
//		流程管理结束
		if(new flow().insertFlow(f)){
			return "succ";
		}else{
			return "succ";
		}
	}

}
